import useSystemStore from '@/store/system'

export default app => {
  app.directive('btn', {
    mounted (el, binding) {
      // 所有按钮
      const systemStore = useSystemStore()

      /**
       * path 当前路由
       * arg 按钮权限名称
       **/
      const { value: { path }, arg } = binding

      const arr = systemStore.btns[path]
      if (arr) {
        if (!arr.some((item) => item.btn === arg)) el.parentNode.removeChild(el)
      } else {
        el.parentNode.removeChild(el)
      }
    }
  })
}
